package com.ideal.frame.prefix.controller;

import com.ideal.frame.common.dto.ResponseModel;
import com.ideal.frame.node.form.search.RootNodeSyncParams;
import com.ideal.frame.prefix.dto.PrefixNextTbForm;
import com.ideal.frame.prefix.entity.PrefixNetxTb;
import com.ideal.frame.prefix.form.search.PrefixSyncParams;
import com.ideal.frame.prefix.service.PrefixNextTbService;
import org.checkerframework.checker.units.qual.Prefix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: liudingsheng
 * @Date: 2021/8/27
 * @Description:
 */
@RestController
@RequestMapping("/prefix")
public class PrefixController {

    @Autowired
    private PrefixNextTbService prefixNextTbService;

    @PostMapping("/sync/findBySyncTime")
    public ResponseModel findBySyncTime(@RequestBody PrefixSyncParams params) {
        return ResponseModel.success(prefixNextTbService.findOtherBySyncTime(params));
    }

    @PostMapping("/sync/syncPrefixData")
    public ResponseModel syncPrefixData(@RequestBody List<PrefixNetxTb> list) {
        prefixNextTbService.syncPrefixData(list);
        return ResponseModel.success();
    }

    @PostMapping("/page")
    public ResponseModel page(@RequestBody PrefixNextTbForm form) {
        return ResponseModel.success(prefixNextTbService.getPage(form));
    }

    @PostMapping("/savePrefixNetxTb")
    public ResponseModel savePrefixNetxTb(@RequestBody PrefixNetxTb prefixNetxTb) {
        prefixNextTbService.savePrefixNetxTb(prefixNetxTb);
        return ResponseModel.success();
    }

    @GetMapping("/getByNodeId/{nodeId}")
    public ResponseModel getByNodeId(@PathVariable Integer nodeId) {
        return ResponseModel.success(prefixNextTbService.getByNodeId(nodeId));
    }

    @GetMapping("/getAllByOrgId")
    public ResponseModel getAllByOrgId(@RequestParam(required = false) String orgId) {
        return ResponseModel.success(prefixNextTbService.getAllByOrgId(orgId));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseModel delete(@PathVariable Long id) {
        prefixNextTbService.delete(id);
        return ResponseModel.success();
    }

    @GetMapping("/checkHasPrefix")
    public ResponseModel checkHasPrefix(@RequestParam(required = false) Long id, @RequestParam String prefix) {
        return ResponseModel.success(prefixNextTbService.checkHasPrefix(prefix, id));
    }

    @GetMapping("/checkHasBindOrg")
    public ResponseModel checkHasBindOrg(@RequestParam(required = false) Long id, @RequestParam Long orgId) {
        return ResponseModel.success(prefixNextTbService.checkHasBindOrg(orgId, id));
    }

    @GetMapping("/getCurrentNodePrefix")
    public ResponseModel getCurrentNodePrefix() {
        return ResponseModel.success(prefixNextTbService.getCurrentNodePrefix());
    }
}
